package cn.tedu.oa.department.service.impl;


import cn.tedu.oa.basicInfo.pojo.vo.BasicInfoVO;
import cn.tedu.oa.department.mapper.DepartmentMapper;
import cn.tedu.oa.department.pojo.dto.DepartmentQuery;
import cn.tedu.oa.department.pojo.dto.DepartmentSaveParam;
import cn.tedu.oa.department.pojo.eneity.Department;
import cn.tedu.oa.department.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public void delete(Integer id) {
        log.debug("删除业务，参数：{}",id);
        departmentMapper.delete(id);
    }

    @Override
    public void save(DepartmentSaveParam departmentSaveParam) {
        log.debug("保存业务，参数：{}",departmentSaveParam);
        Department department = new Department();
        BeanUtils.copyProperties(departmentSaveParam,department);
        if (department.getId()==null){
            department.setCreateTime(new Date());
            departmentMapper.insert(department);

        }else{
            departmentMapper.update(department);
        }
        }

    @Override
    public List<BasicInfoVO> select(DepartmentQuery departmentQuery) {
    log.debug("查询业务，参数：{}",departmentQuery);
    List<BasicInfoVO> list = departmentMapper.select(departmentQuery);
    return list;
    }

    @Override
    public List<BasicInfoVO> selectParent(DepartmentQuery departmentQuery) {
        log.debug("查询业务，参数：{}",departmentQuery);
        List<BasicInfoVO> list = departmentMapper.select(departmentQuery);
        return list;
    }
}
